#include<iostream>
#include<fstream>
#include<string>

struct Student {
    char name[15];
    char number[11];
    short score;
};

struct Recoder {
    int a;
    int b;
    int c;
    int d;
    int e;
};

int GetRecoder(const char *, Recoder *);

int main(){
    // std::ifstream filein;
    // filein.open("student.da", std::ios::in);
    // Student stu;
    Recoder rec{0, 0, 0, 0, 0};
    int count = GetRecoder("studentmark.da", &rec);
    if(count){
        std::cout << count << " students all, the grades is:" << std::endl;
        std::cout << "A:\t" << rec.a << std::endl
                << "B:\t" << rec.b << std::endl
                << "C:\t" << rec.c << std::endl
                << "D:\t" << rec.d << std::endl
                << "E:\t" << rec.e << std::endl;
    }else{
        perror("failed to get recode:");
    }

    getchar();
    getchar();
    return 0;
}

int GetRecoder(const char path[], Recoder* rec){
    std::ifstream filein;
    try{
        filein.open(path, std::ios::in);
    }
    catch(...){
        perror("Cannot open the file.");
        return 0;
    }

    Student s;
    int count {0};

    while(!filein.eof()){
    //while(filein.peek()!=EOF){
        count++;
        // std::cout << "conut" << std::endl;
        filein.get(s.name, 15, '#');
        filein.ignore(1);
        filein.get(s.number, 11, '#');
        filein.ignore(1);
        filein >> s.score;
        filein.ignore(1);

        if(s.score < 60){
            rec->e++;
        }else if(s.score < 70){
            rec->d++;
        }else if(s.score < 80){
            rec->c++;
        }else if(s.score < 90){
            rec->b++;
        }else if(s.score <= 100){
            rec->a++;
        }
    }
    filein.close();
    return count;
}